from user.models import Role, UserRole
from user.serializers import RoleAuthSerializer
from user.serializers import UserLoginSerializer

import logging
logger = logging.getLogger(__name__)

def jwt_response_payload_handler(token, user=None, request=None):
    # 自定义响应体
    role_id = UserRole.objects.get(user_id=user.id).role_id  # 获取角色id
    return {
        "token": token,
        "user": UserLoginSerializer(user).data,
        "auth": RoleAuthSerializer(Role.objects.get(id=role_id)).data["auth"]  # 根据角色id获取菜单
    }
